package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.bean.MainMenu;
import com.example.demo.dao.MenuDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class MenuController {
    @Autowired
    MenuDao menuDao;
    @RequestMapping("/menu")
    public  String getAllMenu(){

        List<MainMenu> list=menuDao.getMenus();
        HashMap<String,Object>hashMap=new HashMap<>();
        if (list!=null){
            hashMap.put("menus",list);
            hashMap.put("flag",200);
        }else {
            hashMap.put("flag",404);
        }
        String res= JSON.toJSONString(hashMap);


        return res;
    }

}
